import axios from 'axios';

/**
 * 创建支付订单
 * @param {Object} params 支付订单参数
 * @param {number} params.amount 充值金额
 * @param {number} params.paymentType 支付类型 1-微信支付，2-支付宝支付
 * @param {string} params.packageType 套餐类型 CUSTOM-自定义充值，VIP-会员套餐，EMAIL-邮件套餐
 * @param {number} params.packageId 套餐ID，用于VIP和EMAIL套餐
 * @param {number} params.packagePoints 套餐点数/额度
 * @param {string} params.packageDuration 套餐时长，用于VIP套餐和EMAIL套餐
 * @param {number} params.packageLevel 套餐等级，用于EMAIL套餐
 * @param {string} params.description 充值描述
 * @param {string} params.phone 用户手机号
 * @returns {Promise}
 */
export const createPaymentOrder = (params) => {
  return axios.post('/api/payment/order/create', params, {
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`
    }
  }).then(res => res.data);
};

/**
 * 查询支付订单状态
 * @param {string} orderNo 订单号
 * @returns {Promise}
 */
export const queryPaymentStatus = (orderNo) => {
  return axios.get(`/api/payment/order/query`, {
    params: { orderNo },
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`
    }
  }).then(res => res.data);
};

/**
 * 取消支付订单
 * @param {string} orderNo 订单号
 * @returns {Promise}
 */
export const cancelPaymentOrder = (orderNo) => {
  return axios.post('/api/payment/order/cancel', { orderNo }, {
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`
    }
  }).then(res => res.data);
};

/**
 * 获取支付记录
 * @param {Object} params 查询参数
 * @param {string} params.orderNo 订单号，可选
 * @param {string} params.phone 用户手机号，可选
 * @param {number} params.paymentType 支付类型，可选
 * @param {number} params.status 支付状态，可选
 * @returns {Promise}
 */
export const getPaymentRecords = (params) => {
  return axios.get('/api/payment/records', {
    params,
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`
    }
  }).then(res => res.data);
}; 